package KuaiPaiTest;

import java.util.Arrays;

/**
 * @author 刘全
 * @date 2021/7/25
 */
public class KuaiPai {
    public static void main(String[] args) {
        int[] arr = {3, 6, 2, 8, 4};
        method(0, arr.length - 1, arr);
        System.out.println(Arrays.toString(arr));
    }

    private static void method(int left, int right, int[] arr) {
        int left0 = left;
        int right0 = right;
        if (left > right) {
            return;
        }
        while (left != right) {
            while (arr[right] >= arr[left0] && right > left) {
                right--;
            }
            while (arr[left] <= arr[left0] && right > left) {
                left++;
            }
            int temp = arr[left];
            arr[left] = arr[right];
            arr[right] = temp;
        }
        int temp = arr[left0];
        arr[left0] = arr[left];
        arr[left] = temp;
        method(left0, right - 1, arr);
        method(right + 1, right0, arr);
    }
}
